//
//  ZCOrderDetailLogisticsCell.m
//  ZCJZ
//
//  Created by sujeking on 2019/3/7.
//  Copyright © 2019年 jeking. All rights reserved.
//

#import <Masonry.h>
#import <BlocksKit+UIKit.h>
#import <Toast.h>
#import "ZCOrderDetailLogisticsCell.h"
#import "TBCityIconFont.h"
@interface ZCOrderDetailLogisticsCell()

@property (weak, nonatomic) IBOutlet UIImageView *imv;
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
@property (weak, nonatomic) IBOutlet UILabel *dateLabel;
@property (weak, nonatomic) IBOutlet UILabel *infoLabel;


@end


@implementation ZCOrderDetailLogisticsCell

- (void)awakeFromNib {
  [super awakeFromNib];
  [self setupSubViews];
}

- (void)setupSubViews {
  self.selectionStyle = UITableViewCellSelectionStyleNone;
  UIImage *img = [UIImage iconWithInfo:TBCityIconInfoMake(@"\U0000e628", 20, [generalToolBox getColorWithHexadecimalColorStr:@"0x666666"])];
  self.imv.image = img;
  
  self.contentLabel.text = nil;
  self.dateLabel.text = nil;
  self.infoLabel.text = nil;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  [super setSelected:selected animated:animated];
}

- (void)setDict:(NSDictionary *)dict {
  if ([dict isKindOfClass:[NSString class]] || dict == nil) {
    return;
  }
  _dict = dict;
  NSString *logistics_sn = [dict valueForKey:@"logistics_sn"];
  if (logistics_sn != nil && logistics_sn.length != 0) {
    self.contentLabel.text = [NSString stringWithFormat:@"物流单号 %@",logistics_sn];
    
    UIButton *on = [self getcopyBtn];
    [self.contentView addSubview:on];
    [on mas_makeConstraints:^(MASConstraintMaker *make) {
      make.width.mas_equalTo(40);
      make.height.mas_equalTo(18);
      make.centerY.mas_equalTo(self.contentLabel);
      make.left.mas_equalTo(self.contentLabel.mas_right).offset(5);
    }];
    
    [on bk_addEventHandler:^(id sender) {
      UIPasteboard *past = [UIPasteboard generalPasteboard];
      past.string = [self.dict valueForKey:@"logistics_sn"];
      UIWindow *window = [UIApplication sharedApplication].keyWindow;
      [window makeToast:@"复制成功" duration:2.0 position:CSToastPositionCenter];
    } forControlEvents:UIControlEventTouchUpInside];
    
  } else {
    self.contentLabel.text = @"物流单号 无";
  }
  
  self.contentLabel.textColor = [generalToolBox getColorWithHexadecimalColorStr:@"0x666666"];
  self.dateLabel.text = [dict valueForKey:@"updated_at"];
  
  if ([[dict valueForKey:@"record"] isKindOfClass:[NSDictionary class]]) {
    NSDictionary *record = [dict valueForKey:@"record"];
    self.infoLabel.text = [record valueForKey:@"context"];
  }
}

- (UIButton *)getcopyBtn {
  UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
  btn.titleLabel.font = [UIFont systemFontOfSize:12];
  [btn setTitleColor:[generalToolBox getColorWithHexadecimalColorStr:@"0x666666"] forState:UIControlStateNormal];
  btn.layer.borderWidth = 0.5f;
  btn.layer.borderColor = [generalToolBox getColorWithHexadecimalColorStr:@"0x666666"].CGColor;
  [btn setTitle:@"复制" forState:UIControlStateNormal];
  return btn;
}


@end
